﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LogException
{
    /// <summary>
    /// 异常处理提示窗体
    /// </summary>
    public partial class ErrorForm : Form
    {
        public ErrorForm(Exception ex)
        {
            InitializeComponent();
            this._exception = ex;
            this.Load += ErrorForm_Load;
        }

        #region 窗体打开时，初始化异常信息
        private Exception _exception = null;
        void ErrorForm_Load(object sender, EventArgs e)
        {
            this.rtb_ExceptionMsg.Text = this._exception.Message;
            this.rtb_ExceptionDetail.Text = this._exception.StackTrace;
        }
        #endregion

        #region 展开/收缩详细信息
        /// <summary>
        /// 是否已扩展
        /// </summary>
        private bool _bExtent = true;
        private void btn_Detail_Click(object sender, EventArgs e)
        {
            if (this._bExtent)
            {
                this.btn_Detail.Text = "↑详细信息";
                this.Height = 400;
                this._bExtent = false;
            }
            else
            {
                this.btn_Detail.Text = "↓详细信息";
                this.Height = 200;
                this._bExtent = true;
            }
        }
        #endregion

        /// <summary>
        /// 退出，进程关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Quite_Click(object sender, EventArgs e)
        {
            Application.Exit();
            Environment.Exit(0);
        }

        /// <summary>
        /// 关闭当前窗体，忽略当前异常
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Continue_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
